define(function(require, exports, module) {

	"use strict";
	require("mui");
	require("jquery");
	var abpUse = require("../abp.js");
	var abp = abpUse.abpstart;
	var template = require("template");

	var getFunList = require("../getFunList/getFunList.js"); //函数配置js
	var updateSell = require("../newOrder/updateSell");
	var whId = 0;
	var catalogId = 0;

	getFunList.SortList("SortList", "#sortListShow"); //获取货品类别列表

	$(function() {
		var sellId = sessionStorage.getItem("sellId"); //销售记录ID
		var PirchaseID = sessionStorage.getItem("PirchaseID"); //采购记录ID
		var allocateID = sessionStorage.getItem("allocateID"); //调拨记录ID
		var outPirchaseID = sessionStorage.getItem("outPirchaseID"); //采购入库ID
		var salesOutId = sessionStorage.getItem("salesOutId"); //销售出库ID

		var goodsLists = JSON.parse(sessionStorage.getItem("goodsInfoList"));
		var sellData = JSON.parse(sessionStorage.getItem("sellData")); //销售订单 采购订单
		var allotData = JSON.parse(sessionStorage.getItem("allotData")); //调拨记录
		var inPurchaseData = JSON.parse(sessionStorage.getItem("inPurchaseData")); //采购入库
		var salesData = JSON.parse(sessionStorage.getItem("salesData")); //销售出库
		if(sessionStorage.goodsInfoList) {
			var goodsBuyNum = eval(sessionStorage.goodsInfoList).length;
			$("#goodsBuyNum").text(goodsBuyNum);
		}
		//销售订单
		if(sellId && sellData) {
			if(goodsLists) {
				var goodsBuyNum = sellData.sellDetail.length + goodsLists.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			} else {
				var goodsBuyNum = sellData.sellDetail.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			}
		}
		//采购订单
		if(PirchaseID && sellData) {
			if(goodsLists) {
				var goodsBuyNum = sellData.buyDetail.length + goodsLists.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			} else {
				var goodsBuyNum = sellData.buyDetail.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			}
		}
		//调拨记录ID
		if(allocateID && allotData) {
			if(goodsLists) {
				var goodsBuyNum = allotData.whAllocateDetail.length + goodsLists.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			} else {
				var goodsBuyNum = allotData.whAllocateDetail.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			}
		}
		//采购入库ID
		if(outPirchaseID && inPurchaseData) {
			if(goodsLists) {
				var goodsBuyNum = inPurchaseData.buyInputDetail.length + goodsLists.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			} else {
				var goodsBuyNum = inPurchaseData.buyInputDetail.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			}
		}
		//销售出库ID
		if(salesOutId && salesData) {
			if(goodsLists) {
				var goodsBuyNum = salesData.sellOutputDetail.length + goodsLists.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			} else {
				var goodsBuyNum = salesData.sellOutputDetail.length;
				$("#goodsBuyNum").text(goodsBuyNum);
			}
		}

		mui("body").on("tap", ".product-list", function(e) { //本地储存点击货品信息
			e.stopPropagation();
			sessionStorage.flags = "show";

			var goodsid = $(this).data("id");
			sessionStorage.setItem('data-stockQuery', JSON.stringify(getFunList.dataCached[goodsid]));

			sessionStorage.removeItem("formIndex");
		});

		//首页客户列表返回
		//返回清除缓存
		var commonBack = require("commonBack");
		//钉钉返回
		require('http://g.alicdn.com/ilw/ding/0.8.9/scripts/dingtalk.js');
		var dingTalkNav = require('dd_config');
		//首页进入标识
		if(sessionStorage.getItem("goodsHome") == "goodsHome") {
			mui("body").on("tap", ".product-list-back", function() {
				commonBack.secondBack();
			});

			dingTalkNav.LeftNavBar(commonBack.secondBack);
			//ad
			dingTalkNav.leftAndroid(commonBack.secondBack);
		} else {
			mui("body").on("tap", ".product-list-back", function() {
				mui.back();
			});
			//ios
			dingTalkNav.LeftNavBar();
			//ad
			dingTalkNav.leftAndroid();
		}

		//已选商品及完成按钮点击事件
		mui("body").on("tap", ".mui-chioce .mui-btn-block", function() {
			sessionStorage.removeItem("productSelectSource");
		});
	});

});